"""
 -*- coding: utf-8-*-
 @File: api_dept.py
 @Author: chen
 @time: 2023/10/22/ 17:07
"""
from hogwartsHomework.homework_api_auto.dev.api_base import BaseApi
from hogwartsHomework.homework_api_auto.dev.api_token import Token


class Dept(BaseApi):

    def __init__(self):
        token = Token().get_token()["access_token"]
        self.param["access_token"] = token

    def create(self, name, dep_id=None):
        path = "/cgi-bin/department/create"
        data = {
            "name": name,
            "name_en": "meng_de",
            "parentid": 1,
            "order": 1,
            "id": dep_id
        }
        resp = self.send_req("post", path, json=data)
        return resp.json()

    def update(self, name, dep_id):
        path = "/cgi-bin/department/update"
        data = {
            "id": dep_id,
            "name": name,
            "name_en": "li_yue",
            "parentid": 1,
            "order": 1
        }
        resp = self.send_req("post", path, json=data)
        return resp.json()

    def delete(self, dep_id):
        """删除部门"""
        path = "/cgi-bin/department/delete"
        self.param["id"] = dep_id
        resp = self.send_req("get", path)
        return resp.json()

    def simplelist(self, dep_id=None):
        """获取子部门ID列表"""
        path = "/cgi-bin/department/simplelist"
        self.param["id"] = dep_id
        resp = self.send_req("get", path)
        return resp.json()

    # def dept_id(self,name):
    #     res = self.simplelist()


if __name__ == '__main__':
    # name = "蒙德"
    # dep_id = 1001
    d0 = Dept()
    # d0.create(name, dep_id)
    d0.simplelist()
    # d0.simple_detail()
    # d0.update(name, dep_id)
    # d0.delete(dep_id)
